<?php
/**
 * @link https://www.kancloud.cn/cleverstone/ymb2
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

namespace builder\widget\ajax;

use yii\helpers\Html;
use yii\helpers\Json;
use yii\base\InvalidConfigException;

/**
 * Ajax:轮播图
 * ```php
 * Carousel::widget([
 *          'id' => 'FFFFFFFFFFFFFFFFFFFFFFFFF',//如果用于页面遍历中,则必须指定不同`id`!
 *          'options' => [
 *              'style' => 'width:100px;height:100px;',
 *          ],
 *          //'controls' => false,
 *          'items' => [
 *               [
 *                  'content' => '<img ym2-full-image style="width:100px;height:100px;" src="https://buerzz.damanzj.com/upload/image/goods_manager/G20230720164108385/album_images/202306291606534csyPMlILJ.jpg"/>',
 *               ],
 *               [
 *                  'content' => '<img ym2-full-image style="width:100px;height:100px;" src="https://buerzz.damanzj.com/upload/image/goods_manager/G20230720164108385/album_images/20230402153138IlzZxeOSV1.jpg"/>',
 *               ],
 *               [
 *                  'content' => '<img ym2-full-image style="width:100px;height:100px;" src="https://buerzz.damanzj.com/upload/image/goods_comment/14219/6718/20230720145807HmPqj8T2R5.png"/>',
 *               ],
 *          ],
 * ]);
 * ```
 * @author cleverstone
 * @since ym2.0
 */
class Carousel extends \yii\bootstrap4\Carousel
{
    public static $autoIdPrefix = 'B4-Carousel';

    /**
     * {@inheritdoc}
     * @throws InvalidConfigException
     */
    public function run()
    {
        $this->options['ym2-bootstrap-plugin'] = 'carousel';
        $this->options['plugin-config'] = !empty($this->clientOptions) ? Json::encode($this->clientOptions) : '';

        return implode("\n", [
                Html::beginTag('div', $this->options),
                $this->renderIndicators(),
                $this->renderItems(),
                $this->renderControls(),
                Html::endTag('div')
            ]) . "\n";
    }
}